<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/common.jsp"%>

<script type="text/javascript" src="${basePath}/js/jQuery-File-Upload-master/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="${basePath}/js/jQuery-File-Upload-master/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="${basePath}/js/jQuery-File-Upload-master/jquery.fileupload.js"></script>
<script type="text/javascript" src="${basePath}/js/jQuery-File-Upload-master/jquery.fileupload-process.js"></script>

<div class="am-cf am-padding am-padding-bottom-0">
	<div class="am-fl am-cf">
		<strong class="am-text-primary am-text-lg">系统参数</strong> / <small>System
			settings</small>
	</div>
</div>

<div class="am-tabs am-margin" data-am-tabs="">
	<ul class="am-tabs-nav am-nav am-nav-tabs">
		<li class="am-active"><a href="#company-div">公司信息</a></li>
		<li><a href="#webSite-div">网站信息</a></li>
		<li><a href="#workTime-div">工作时间</a></li>
		<li><a href="#pictures-div">首页轮播</a></li>
		<li><a href="#partners-div">合作伙伴</a></li>
	</ul>

	<div class="am-tabs-bd">
		<!-- 公司div Start -->
		<div class="am-tab-panel am-fade am-in am-active" id="company-div">
			<form class="am-form am-form-horizontal validate-form" id="companyForm">				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">公司名称</div>
					<div class="am-u-sm-8 am-u-md-4 am-form-group">
						<input type="text" id="companyName" name="companyName" placeholder="请输入你的公司名称"
							value="${companyT.companyName }" required data-validation-message="公司名称不能为空" />
					</div>
					<div class="am-hide-sm-only am-u-md-6" style="color: red;">*必填</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">公司地址</div>
					<div class="am-u-sm-8 am-u-md-4 am-form-group">
						<input type="text" id="companyAddress" name="companyAddress" placeholder="请输入你的公司地址" value="${companyT.companyAddress }"
							required data-validation-message="公司地址不能为空" />
					</div>
					<div class="am-hide-sm-only am-u-md-6" style="color: red;">*必填</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">公司电话</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<input type="text" id="companyPhoneNumber" name="companyPhoneNumber" placeholder="请输入你的公司名称" value="${companyT.companyPhoneNumber }" />
					</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">公司邮箱</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<input type="text" id="companyEmail" name="companyEmail" placeholder="请输入你的公司邮箱" value="${companyT.companyEmail}" />
					</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">公司图标</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<div class="am-form-group am-form-file">
							<button type="button" class="am-btn am-btn-default am-btn-sm">
								<i class="am-icon-upload">上传图标 </i>
							</button>
							<span id="icoDiv">
								<image src="${companyT.iconPath }" />
								<input type="hidden" name="iconPath" id="iconPath" value="${companyT.iconPath }" />
							</span>
							<input id="icoupload" type="file" name="file" multiple="false"
								accept="image/x-icon" />
						</div>
						<div class="am-progress am-progress-striped am-active" id="icoBar" style="margin: 5px; width: 300px;">
							<div class="am-progress-bar am-progress-bar-success" id="icoProcessBar"></div>
						</div>
						<span style="text-align: center; font-size: 14px; color: gray;">请上传附件大小10M以内。请上传格式为ico文件</span>
					</div>
				</div>
			</form>
		</div>
		<!-- 公司div End -->
		
		<!-- 网站信息div Start -->
		<div class="am-tab-panel am-fade" id="webSite-div">
			<form class="am-form am-form-horizontal validate-form" id="webSiteForm">				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">网站名称</div>
					<div class="am-u-sm-8 am-u-md-4 am-form-group">
						<input type="text" id="name" name="name" placeholder="请输入你的网站名称" value="${webSiteT.name}"
							required data-validation-message="网站名称不能为空" />
					</div>
					<div class="am-hide-sm-only am-u-md-6" style="color: red;">*必填</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">网站备案号</div>
					<div class="am-u-sm-8 am-u-md-4 am-form-group">
						<input type="text" id="ICP" name="ICP" placeholder="请输入你的网站备案号" value="${webSiteT.ICP}"
							required data-validation-message="网站备案号不能为空" />
					</div>
					<div class="am-hide-sm-only am-u-md-6" style="color: red;">*必填</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">网站描述</div>
					<div class="am-u-sm-8 am-u-md-4 am-form-group">
						<input type="text" id="description" name="description" placeholder="请输入你的网站描述" value="${webSiteT.description}" />
					</div>
					<div class="am-hide-sm-only am-u-md-6" style="color: red;">此项内容为网站的描述，会被搜索引擎搜索</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">网站关键字</div>
					<div class="am-u-sm-8 am-u-md-4 am-form-group">
						<input id="keywords-tag" name="keywords" type="text" value="${webSiteT.keywords }" data-am-tagsinput />
					</div>
					<div class="am-hide-sm-only am-u-md-6" style="color: red;">此项内容为网站的关键字，会被搜索引擎搜索</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">网站LOGO</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<div class="am-form-group am-form-file">
							<button type="button" class="am-btn am-btn-default am-btn-sm">
								<i class="am-icon-upload">上传LOGO </i>
							</button>
							<span id="logoDiv">
								<image src="${webSiteT.logoPath }" />
								<input type="hidden" name="logoPath" id="logoPath" value="${webSiteT.logoPath }" />
							</span>
							<input id="logoupload" type="file" name="file" multiple="false"
								accept="image/bmp,image/gif,image/pipeg,image/jpeg,image/svg+xml,image/x-portable-anymap,image/x-portable-bitmap,image/x-rgb" />
						</div>
						<div class="am-progress am-progress-striped am-active" id="logoBar" style="margin: 5px; width: 300px;">
							<div class="am-progress-bar am-progress-bar-success" id="logoProcessBar"></div>
						</div>
						<span style="text-align: center; font-size: 14px; color: gray;">请上传附件大小10M以内。请上传图片文件</span>
					</div>
				</div>
			</form>
		</div>
		<!-- 网站信息div End -->
		
		<!-- 工作时间div Start -->
		<div class="am-tab-panel am-fade" id="workTime-div">
			<form class="am-form am-form-horizontal validate-form" id="workTimeForm">				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">工作日（开始）</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<input type="text" id="workDayStart" name="workDayStart" placeholder="请输入你的开始工作日" value="${workTimeT.workDayStart}" />
					</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">工作日（结束）</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<input type="text" id="workDayEnd" name="workDayEnd" placeholder="请输入你的结束工作日" value="${workTimeT.workDayEnd}"/>
					</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">工作时间（开始）</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<input type="text" id="workTimeStart" name="workTimeStart" placeholder="请输入你工作日的开始工作时间" value="${workTimeT.workTimeStart}" />
					</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">工作时间（结束）</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<input type="text" id="workTimeEnd" name="workTimeEnd" placeholder="请输入你工作日的结束工作结束" value="${workTimeT.workTimeEnd}" />
					</div>
				</div>
			</form>
		</div>
		<!-- 工作时间div End -->
		
		<!-- 首页轮播div Start -->
		<div class="am-tab-panel am-fade" id="pictures-div">
			<form class="am-form am-form-horizontal validate-form" id="picturesForm">				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">图片轮播</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<div class="am-form-group am-form-file">
							<button type="button" class="am-btn am-btn-default am-btn-sm">
								<i class="am-icon-upload">上传图片 </i>
							</button>
							<input id="imageupload" type="file" name="file" multiple="false"
								accept="image/bmp,image/gif,image/pipeg,image/jpeg,image/svg+xml,image/x-portable-anymap,image/x-portable-bitmap,image/x-rgb" />
						</div>
						<div class="am-progress am-progress-striped am-active" id="imageBar" style="margin: 5px; width: 300px;">
							<div class="am-progress-bar am-progress-bar-success" id="imageProcessBar"></div>
						</div>
						<span style="text-align: center; font-size: 14px; color: gray;">请上传附件大小10M以内。请上传图片文件</span>
					</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">图片轮播详情</div>
					<div class="am-u-sm-8 am-u-md-10 am-u-end am-form-group" id="pictureDiv">
						<c:forEach var="picture" items="${ picturesT}" varStatus="s">
						<c:if test="${s.index == (picturesT.size() - 1)}">
							<c:set var="end" value="am-u-end" />
						</c:if>
						<div class=" am-u-sm-12 am-u-md-6 picture-panel ${end }">
							<div class="am-panel am-panel-default">
								<div class="am-panel-hd am-cf"
									data-am-collapse="{target: '#collapse-panel-${s.index }'}">${picture.imageName }<span
										class="am-icon-chevron-down am-fl"></span>
										<span class="am-icon-times am-fr" onclick="removeThisPicture(this)"></span>
								</div>
								<div class="am-panel-bd am-collapse am-in" id="collapse-panel-${s.index }">
									<ul class="am-list admin-content-file">
										<li><img src="${picture.imagePath }" onclick="changePictures(this)"
											style="max-height: 300px; max-width: 100%" /></li>
										<li class="am-form-group"><strong>排序规则</strong>
										<input type="text" pattern="^\d{0,3}$" placeholder="请输入排序规则，数字并且不能超过三位" required data-validation-message="排序规则不能为空且不能重复"
											name="orderNumber" value="${picture.orderNumber}" /></li>
										<li><strong>文字描述</strong> <input type="text"
											name="words" value="${picture.words}" /></li>
										<li><strong>点击时的路径</strong> <input type="text"
											name="url" value="${picture.url}" /></li>
										<input type="hidden"
											name="imagePath" value="${picture.imagePath}" />
										<input type="hidden"
											name="imageName" value="${picture.imageName}" />
									</ul>
								</div>
							</div>
						</div>
						</c:forEach>
					</div>
				</div>
			</form>
		</div>
		<!-- 首页轮播div End -->
		
		<!-- 合作伙伴div Start -->
		<div class="am-tab-panel am-fade" id="partners-div">
			<form class="am-form am-form-horizontal validate-form" id="partnersForm">				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">合作伙伴</div>
					<div class="am-u-sm-8 am-u-md-4 am-u-end am-form-group">
						<div class="am-form-group am-form-file">
							<button type="button" class="am-btn am-btn-default am-btn-sm">
								<i class="am-icon-upload">上传图片 </i>
							</button>
							<input id="partnerupload" type="file" name="file" multiple="false"
								accept="image/bmp,image/gif,image/pipeg,image/jpeg,image/svg+xml,image/x-portable-anymap,image/x-portable-bitmap,image/x-rgb" />
						</div>
						<div class="am-progress am-progress-striped am-active" id="partnerBar" style="margin: 5px; width: 300px;">
							<div class="am-progress-bar am-progress-bar-success" id="partnerProcessBar"></div>
						</div>
						<span style="text-align: center; font-size: 14px; color: gray;">请上传附件大小10M以内。请上传图片文件</span>
					</div>
				</div>
				
				<div class="am-g am-margin-top">
					<div class="am-u-sm-4 am-u-md-2 am-text-right">合作伙伴详情</div>
					<div class="am-u-sm-8 am-u-md-10 am-u-end am-form-group" id="partnerDiv">
						<c:forEach var="partner" items="${ partnersT}" varStatus="s">
						<c:if test="${s.index == (picturesT.size() - 1)}">
							<c:set var="end" value="am-u-end" />
						</c:if>
						<div class=" am-u-sm-12 am-u-md-6 partner-panel ${end }">
							<div class="am-panel am-panel-default">
								<div class="am-panel-hd am-cf"
									data-am-collapse="{target: '#partner-panel-${s.index }'}">${partner.companyName }<span
										class="am-icon-chevron-down am-fl"></span>
										<span class="am-icon-times am-fr" onclick="removeThisPartner(this)"></span>
								</div>
								<div class="am-panel-bd am-collapse am-in" id="partner-panel-${s.index }">
									<ul class="am-list admin-content-file">
										<li><img src="${partner.iconPath }" onclick="changePartners(this)"
											style="max-height: 50px; max-width: 100%" /></li>
										<li class="am-form-group"><strong>排序规则</strong>
										<input type="text" pattern="^\d{0,3}$" placeholder="请输入排序规则，数字并且不能超过三位" required data-validation-message="排序规则不能为空且不能重复"
											name="orderNumber" value="${partner.orderNumber}" /></li>
										<li class="am-form-group"><strong>公司名称</strong> <input type="text" required
											data-validation-message="公司名称不能为空" name="companyName" value="${partner.companyName}" /></li>
										<li><strong>点击时的路径</strong> <input type="text"
											name="url" value="${partner.url}" /></li>
										<input type="hidden"
											name="iconPath" value="${partner.iconPath}" />
									</ul>
								</div>
							</div>
						</div>
						</c:forEach>
					</div>
				</div>
			</form>
		</div>
		<!-- 合作伙伴div End -->
	</div>
</div>

<div class="am-margin">
	<button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="saveCurrent()">提交保存</button>
	<button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="exitShow()">放弃保存</button>
</div>

<script>
	var saveCurrent = function(){
		$(".am-active").find("form").submit();
	};

	var systemParam = {
		save : function(seqId){
			if($(".am-active").find("form").attr("id").replace(/Form/g,'') == 'company'){
				var company = {};
				company["companyName"] = $("#companyName").val();
				company["companyAddress"] = $("#companyAddress").val();
				company["companyPhoneNumber"] = $("#companyPhoneNumber").val();
				company["companyEmail"] = $("#companyEmail").val();
				company["iconPath"] = $("#iconPath").val();
			}
			if($(".am-active").find("form").attr("id").replace(/Form/g,'') == 'workTime'){
				var workTime = {};
				workTime["workDayStart"] = $("#workDayStart").val();
				workTime["workDayEnd"] = $("#workDayEnd").val();
				workTime["workTimeStart"] = $("#workTimeStart").val();
				workTime["workTimeEnd"] = $("#workTimeEnd").val();
			}
			if($(".am-active").find("form").attr("id").replace(/Form/g,'') == 'webSite'){
				var webSite = {};
				webSite["name"] = $("#name").val();
				webSite["ICP"] = $("#ICP").val();
				webSite["description"] = $("#description").val();
				webSite["keywords"] = $("#keywords-tag").val();
				webSite["logoPath"] = $("#logoPath").val();
			}
			if($(".am-active").find("form").attr("id").replace(/Form/g,'') == 'pictures'){
				var pictures = new Array();
				var orderNumberArray = new Array();
				$("#pictureDiv").find(".am-panel.am-panel-default").each(function(){
					var picture = {};
					var orderNumber = $(this).find("[name='orderNumber']").val();
					picture["orderNumber"] = orderNumber;
					if(orderNumberArray.indexOf(parseInt(orderNumber)) != -1 || orderNumber.length > 3){
						layer.msg("排序规则有误不能为空！不能重复不能超过三位整数！",{icon: 2});
						throw "排序规则有误不能为空！不能重复不能超过三位整数！";
					}
					picture["words"] = $(this).find("[name='words']").val();
					picture["url"] = $(this).find("[name='url']").val();
					picture["imagePath"] = $(this).find("[name='imagePath']").val();
					picture["imageName"] = $(this).find("[name='imageName']").val();
					orderNumberArray.push(parseInt(orderNumber));
					pictures.push(picture);
				});
			}
			if($(".am-active").find("form").attr("id").replace(/Form/g,'') == 'partners'){
				var partners = new Array();
				var orderNumberArray = new Array();
				$("#partnerDiv").find(".am-panel.am-panel-default").each(function(){
					var partner = {};
					var orderNumber = $(this).find("[name='orderNumber']").val();
					partner["orderNumber"] = orderNumber;
					if(orderNumberArray.indexOf(parseInt(orderNumber)) != -1 || orderNumber.length > 3){
						layer.msg("排序规则有误不能为空！不能重复不能超过三位整数！",{icon: 2});
						throw "排序规则有误不能为空！不能重复不能超过三位整数！";
					}
					partner["companyName"] = $(this).find("[name='companyName']").val();
					partner["url"] = $(this).find("[name='url']").val();
					partner["iconPath"] = $(this).find("[name='iconPath']").val();
					partner["imageName"] = $(this).find("[name='imageName']").val();
					orderNumberArray.push(parseInt(orderNumber));
					partners.push(partner);
				});
			}
			var param = {"company": company,"workTime": workTime,"webSite": webSite,"pictures": pictures,"partners":partners};
			// 更新
			$.ajax({
			  url:"/manage/systemParam/save",
			  method: 'POST',  
			  data:{paramJsonStr:JSON.stringify(param)},
			  dataType:'html',
			  success:function(data){
				var result = systemParam.dealSaveCallback(data);
				if(result == true){
					layer.msg("更新成功！",{icon: 1});
					exitShow();
				}
			  },
			  error:function(data){
				layer.msg("连接服务器时遇到错误！", {icon: 2});
			  }
			});
		},
		dealSaveCallback : function(data){
			if(data == "ON_ER"){
				layer.msg("轮播图片排序规则有误不能为空！不能重复不能超过三位整数！",{icon: 2});
			}
			else if(data == "PO_ER"){
				layer.msg("合作伙伴排序规则有误不能为空！不能重复不能超过三位整数！",{icon: 2});
			}
			else{
				return true;
			}
		}
	};
	
	$(function(){
		$('#keywords-tag').tagsinput();
		
		var $form = $('.validate-form');
		
		$form.validator({
			onValid : function(validity) {
				$(validity.field).closest('.am-form-group').find('.am-alert').hide();
			},
			onInValid : function(validity) {
				
				var $field = $(validity.field);
				var $group = $field.closest('.am-form-group');
				var $alert = $group.find('.am-alert');
				// 使用自定义的提示信息 或 插件内置的提示信息
				var msg = $field.data('validationMessage') || this.getValidationMessage(validity);
				
				if (!$alert.length) {
					$alert = $('<div class="am-alert am-alert-danger"></div>').hide().appendTo($group);
				}
				
				$alert.html(msg).show();
			},
			submit : function() {
				var formValidity = this.isFormValid();
				
				// 表单验证未成功
				if (!formValidity) {
					console.warn('验证状态：', '未通过');
				} else{
					systemParam.save();
			   	}
				return false;
			}
		});
		
		// 接收ico文件
		var acceptIcoTypes=/(\.|\/)(ico)$/i;
		$('#icoupload').fileupload({
			url:"${basePath}/uploadImages",
			autoUpload: true,
			iframe : true,
			maxNumberOfFiles : 1,
			add : function(e, data) {
				if (data.files[0].size > 1024*1024*10) {
					 window.parent.layer.alert('上传文件大于10M！', {
						icon : 5
					});
					return;
				}
				if (!(acceptIcoTypes.test(data.files[0].name) || acceptIcoTypes.test(data.files[0].type))) {
					 window.parent.layer.alert('请上传 ico 类型文件！', {
						icon : 5
					});
					return;
				}
				if(data.files[0].name.length > 80){
					window.parent.layer.alert('该文件名太长，请修改后再重试！', {
						icon : 5
					});
					return;
				}
				data.process().done(function() {
					$('#icoBar').fadeIn();
					data.submit();
				});
			},
			progressall : function(e, data) {
				var progress = parseInt(data.loaded / data.total* 100, 10);
				$('#icoProcessBar').css('width', progress + '%');
				$('#icoProcessBar').text(progress + '%');
			},
			done:function(e,data){
				$('#icoBar').html("<div class='am-progress-bar am-progress-bar-success' id='icoProcessBar'></div>");
				if(data && data.result) {
					var html = "";
					html += '<image src="'+data.result.url+'" />';
					html += '<input type="hidden" name="iconPath" id="iconPath" value="'+data.result.url+'" />';
					$("#icoDiv").html(html);
					parent.layer.msg("上传成功", {
					    icon: 1,
					    skin: 'layer-ext-moon'
					});
				} else {
					parent.layer.msg("上传失败", {
					    icon: 2,
					    skin: 'layer-ext-moon'
					});
				}
			}
		});
		
		// 接收LOGO文件
		var acceptIcoTypes=/(\.|\/)(ico)$/i;
		$('#logoupload').fileupload({
			url:"${basePath}/uploadImages",
			autoUpload: true,
			iframe : true,
			maxNumberOfFiles : 1,
			add : function(e, data) {
				if (data.files[0].size > 1024*1024*10) {
					 window.parent.layer.alert('上传文件大于10M！', {
						icon : 5
					});
					return;
				}
				if(data.files[0].name.length > 80){
					window.parent.layer.alert('该文件名太长，请修改后再重试！', {
						icon : 5
					});
					return;
				}
				data.process().done(function() {
					$('#logoBar').fadeIn();
					data.submit();
				});
			},
			progressall : function(e, data) {
				var progress = parseInt(data.loaded / data.total* 100, 10);
				$('#logoProcessBar').css('width', progress + '%');
				$('#logoProcessBar').text(progress + '%');
			},
			done:function(e,data){
				$('#logoBar').html("<div class='am-progress-bar am-progress-bar-success' id='logoProcessBar'></div>");
				if(data && data.result) {
					var html = "";
					html += '<image src="'+data.result.url+'" />';
					html += '<input type="hidden" name="logoPath" id="logoPath" value="'+data.result.url+'" />';
					$("#logoDiv").html(html);
					parent.layer.msg("上传成功", {
					    icon: 1,
					    skin: 'layer-ext-moon'
					});
				} else {
					parent.layer.msg("上传失败", {
					    icon: 2,
					    skin: 'layer-ext-moon'
					});
				}
			}
		});
		
		// 接收图片文件
		$('#imageupload').fileupload({
			url:"${basePath}/uploadImages",
			autoUpload: true,
			iframe : true,
			maxNumberOfFiles : 1,
			add : function(e, data) {
				if (data.files[0].size > 1024*1024*10) {
					 window.parent.layer.alert('上传文件大于10M！', {
						icon : 5
					});
					return;
				}
				
				if(data.files[0].name.length > 80){
					window.parent.layer.alert('该文件名太长，请修改后再重试！', {
						icon : 5
					});
					return;
				}
				data.process().done(function() {
					$('#imageBar').fadeIn();
					data.submit();
				});
			},
			progressall : function(e, data) {
				var progress = parseInt(data.loaded / data.total* 100, 10);
				$('#imageProcessBar').css('width', progress + '%');
				$('#imageProcessBar').text(progress + '%');
			},
			done:function(e,data){
				$('#imageBar').html("<div class='am-progress-bar am-progress-bar-success' id='imageProcessBar'></div>");
				
				if(data && data.result) {
					
					if(changePicturesDiv) {
						changePicturesDiv.find(".am-panel-hd.am-cf").html(data.result.fileName);
						changePicturesDiv.find("img").attr("src",data.result.url);
						changePicturesDiv.find("[name='imagePath']").val(data.result.url);
						changePicturesDiv.find("[name='imageName']").val(data.result.fileName);
					}
					else{
						var $picturePanel = $("#pictureDiv").find(".picture-panel");
						
						var maxId = 0;
						$picturePanel.find(".am-panel-bd.am-collapse").each(function(){
							var currentId = parseInt(this.id.replace(/collapse\-panel\-/g,''));
							if(currentId > maxId){
								maxId = currentId;
							}
						});
						
						var html = "";
						html += '<div class=" am-u-sm-12 am-u-md-6 picture-panel am-u-end"><div class="am-panel am-panel-default">';
						html += '<div class="am-panel-hd am-cf" data-am-collapse="{target: \'#collapse-panel-' + (maxId + 1) + '\'}">';
						html += data.result.fileName;
						html += '<span class="am-icon-chevron-down am-fl"></span><span class="am-icon-times am-fr" onclick="removeThisPicture(this)"></span></div>';
						html += '<div class="am-panel-bd am-collapse am-in" id="collapse-panel-' + (maxId + 1) + '">';
						html += '<ul class="am-list admin-content-file">';
						html += '<li><img src="';
						html += data.result.url;
						html += '" style="max-height: 300px; max-width: 100%" /></li>';
						html += '<li class="am-form-group"><strong>排序规则</strong> <input type="text" pattern="^\\d{0,3}$" placeholder="请输入排序规则，数字并且不能超过三位" required data-validation-message="排序规则不能为空且不能重复" name="orderNumber" value="" /></li>';
						html += '<li><strong>文字描述</strong> <input type="text" name="words" value="" /></li>';
						html += '<li><strong>点击时的路径</strong> <input type="text" name="url" value="" /></li>';
						html += '<input type="hidden" name="imagePath" value="' + data.result.url +'" />';
						html += '<input type="hidden" name="imageName" value="' + data.result.fileName +'" />';
						html +=	'</ul></div></div></div>';
						
						$picturePanel.removeClass("am-u-end");
						$("#pictureDiv").append(html);
					}
					parent.layer.msg("上传成功", {
					    icon: 1,
					    skin: 'layer-ext-moon'
					});
				} else {
					parent.layer.msg("上传失败", {
					    icon: 2,
					    skin: 'layer-ext-moon'
					});
				}
				
				changePicturesDiv = undefined;
			}
		});
		
		// 接收合作伙伴图片
		$('#partnerupload').fileupload({
			url:"${basePath}/uploadImages",
			autoUpload: true,
			iframe : true,
			maxNumberOfFiles : 1,
			add : function(e, data) {
				if (data.files[0].size > 1024*1024*10) {
					 window.parent.layer.alert('上传文件大于10M！', {
						icon : 5
					});
					return;
				}
				
				if(data.files[0].name.length > 80){
					window.parent.layer.alert('该文件名太长，请修改后再重试！', {
						icon : 5
					});
					return;
				}
				data.process().done(function() {
					$('#partnerBar').fadeIn();
					data.submit();
				});
			},
			progressall : function(e, data) {
				var progress = parseInt(data.loaded / data.total* 100, 10);
				$('#partnerProcessBar').css('width', progress + '%');
				$('#partnerProcessBar').text(progress + '%');
			},
			done:function(e,data){
				$('#partnerBar').html("<div class='am-progress-bar am-progress-bar-success' id='partnerProcessBar'></div>");
				
				if(data && data.result) {
					
					if(changePartnersDiv) {
						changePartnersDiv.find(".am-panel-hd.am-cf").html(data.result.fileName);
						changePartnersDiv.find("img").attr("src",data.result.url);
						changePartnersDiv.find("[name='iconPath']").val(data.result.url);
					}
					else{
						var $partnerPanel = $("#partnerDiv").find(".partner-panel");
						
						var maxId = 0;
						$partnerPanel.find(".am-panel-bd.am-collapse").each(function(){
							var currentId = parseInt(this.id.replace(/collapse\-panel\-/g,''));
							if(currentId > maxId){
								maxId = currentId;
							}
						});
						
						var html = "";
						html += '<div class=" am-u-sm-12 am-u-md-6 partner-panel am-u-end"><div class="am-panel am-panel-default">';
						html += '<div class="am-panel-hd am-cf" data-am-collapse="{target: \'#partner-panel-' + (maxId + 1) + '\'}">';
						html += data.result.fileName;
						html += '<span class="am-icon-chevron-down am-fl"></span><span class="am-icon-times am-fr" onclick="removeThisPartner(this)"></span></div>';
						html += '<div class="am-panel-bd am-collapse am-in" id="partner-panel-' + (maxId + 1) + '">';
						html += '<ul class="am-list admin-content-file">';
						html += '<li><img src="';
						html += data.result.url;
						html += '" style="max-height: 300px; max-width: 100%" /></li>';
						html += '<li class="am-form-group"><strong>排序规则</strong> <input type="text" pattern="^\\d{0,3}$" placeholder="请输入排序规则，数字并且不能超过三位" required data-validation-message="排序规则不能为空且不能重复" name="orderNumber" value="" /></li>';
						html += '<li class="am-form-group"><strong>公司名称</strong> <input type="text" required data-validation-message="公司名称不能为空" name="companyName" value="" /></li>';
						html += '<li><strong>点击时的路径</strong> <input type="text" name="url" value="" /></li>';
						html += '<input type="hidden" name="iconPath" value="' + data.result.url +'" />';
						html +=	'</ul></div></div></div>';
						
						$partnerPanel.removeClass("am-u-end");
						$("#partnerDiv").append(html);
					}
					parent.layer.msg("上传成功", {
					    icon: 1,
					    skin: 'layer-ext-moon'
					});
				} else {
					parent.layer.msg("上传失败", {
					    icon: 2,
					    skin: 'layer-ext-moon'
					});
				}
				
				changePartnersDiv = undefined;
			}
		});
	});
	

	// 轮播图片相关	
	var removeThisPicture = function(element){
		$(element).closest(".am-panel.am-panel-default").remove();
	}
	
	var changePicturesDiv;
	
	var changePictures = function(element){
		changePicturesDiv = $(element).closest(".am-panel.am-panel-default");
		$('#imageupload').click();
	}
	// 轮播图片相关
	
	// 合作伙伴相关
	var removeThisPartner = function(element){
		$(element).closest(".am-panel.am-panel-default").remove();
	}
	
	var changePartnersDiv;
	
	var changePartners = function(element){
		changePartnersDiv = $(element).closest(".am-panel.am-panel-default");
		$('#partnerupload').click();
	}
	// 合作伙伴相关
</script>